﻿Imports System.Runtime.InteropServices
Imports System.Windows.Forms

Imports DWGdirect.Colors
Imports DWGdirect.DatabaseServices
Imports DWGdirect.Geometry
Imports DWGdirect.Runtime


Public Class DWGImportForm

  



    Protected mRef As LayerManager
    Protected m_manager As ReadOnlyLayerManager

    Protected textList As New List(Of FText)


    Dim entList As New List(Of FEntity)

    Dim fName As String = ""

    Dim lName As String

   
    Public Sub New(ByRef m As LayerManager, ByVal ln As String)

        ' 此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        ' 在 InitializeComponent() 调用之后添加任何初始化。




        If m Is Nothing Then
            MessageBox.Show("空引用传递！")
            Me.Close()

        End If

        mRef = m

        If ln = "" Then
            MessageBox.Show("层ID不能为空！")
            Me.Close()

        End If

        lName = ln







        m_manager = New ReadOnlyLayerManager(AxMap1)

        AddHandler m_manager.AskForRemoveEntity, AddressOf Me.OnAskRemove
        AddHandler m_manager.EntitySelected, AddressOf Me.OnSelected


        '这里是新加的关于显示的坐标
        AddHandler m_manager.mousePosChanged, AddressOf Me.OnMPosChanged

        AxMap1.CursorMode = MapWinGIS.tkCursorMode.cmNone
        AxMap1.MapCursor = MapWinGIS.tkCursor.crsrMapDefault



    End Sub

    Private Sub DXFImportForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load




    End Sub

    Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
        If txtFileName.Text.Trim() = "" Or Not System.IO.File.Exists(txtFileName.Text.Trim()) Then

            MessageBox.Show("请指定正确的DWG文件", "错误")
            Return
        End If

        If txtSave.Text.Trim() = "" Then
            MessageBox.Show("请指定输出的SHP文件保存位置与名称", "错误")
            Return

        End If

     



        lblMessage.Text = "正在转换请稍后..."


        Me.Cursor = Cursors.WaitCursor

        '清空旧有的逻辑
        entList.Clear()


        m_manager.RemoveLayer("layer")



        '关于已经存在的文件

        Dim strPath(2) As String

        Dim strSave As String = txtSave.Text.Trim()

        strPath(0) = strSave
        strPath(1) = strSave.Substring(0, strSave.Length - 4) + ".dbf"
        strPath(2) = strSave.Substring(0, strSave.Length - 4) + ".shx"

        If System.IO.File.Exists(txtSave.Text.Trim()) Or System.IO.File.Exists(strPath(1)) Or System.IO.File.Exists(strPath(2)) Then
            If DialogResult.Yes = MessageBox.Show("该名称的SHP文件已经存在，请问是否覆盖！", "提示", MessageBoxButtons.YesNo) Then





                For i As Integer = 0 To strPath.Length - 1
                    If System.IO.File.Exists(strPath(i)) Then
                        Try
                            System.IO.File.SetAttributes(strPath(i), IO.FileAttributes.Normal)
                            System.IO.File.Delete(strPath(i))

                        Catch ex As IO.IOException
                            '小阳加入
                            MsgBox("文件重名，请重新导入文件", MsgBoxStyle.OkOnly, "提示")
                            Exit Sub
                        End Try

                    End If
                Next


            Else

                '不替换的话，就直接返回
                Return

            End If


        End If







        Dim shpFile As New MapWinGIS.Shapefile

        Dim b As Boolean = False
        b = shpFile.CreateNew("", MapWinGIS.ShpfileType.SHP_POLYLINE)

        If Not b Then
            MessageBox.Show("SHP文件创建失败！")
            Return
        End If

        b = shpFile.SaveAs(txtSave.Text.Trim())

        If Not b Then
            MessageBox.Show("SHP文件创建失败！请确定此名称的SHP文件并不存在")
            lblMessage.Text = "SHP文件创建失败！请确定此名称的SHP文件并不存在"

            Me.Cursor = Cursors.Default

            Return
        End If


        Dim f As New MapWinGIS.Field

        f = New MapWinGIS.Field
        f.Name = "Name"
        f.Type = MapWinGIS.FieldType.STRING_FIELD
        f.Width = 50

        Dim fd As New MapWinGIS.Field

        fd = New MapWinGIS.Field
        fd.Name = "desc"
        fd.Type = MapWinGIS.FieldType.STRING_FIELD
        fd.Width = 50


        shpFile.StartEditingShapes(True)
        shpFile.EditInsertField(f, 0)
        shpFile.EditInsertField(fd, 1)


        shpFile.StopEditingShapes()


        shpFile.Close()

        Dim poly As New ESMLineLayer("layer", New PolyTool())
        m_manager.LoadLayer(poly, txtSave.Text.Trim())





        Try



            '进行对应的转换，这里测试多线程的应用,结果发现很难用
            bgwTran.RunWorkerAsync()


            'Dim strFileName As String = txtFileName.Text.Trim()

            'TranslateDWG(strFileName)


        Catch ex As Exception

            MessageBox.Show("导入文件错误！错误信息为：" + ex.Message)


        End Try






        'AfterTran()



     
        Me.Cursor = Cursors.Default

       


    End Sub

    Protected Sub TranslateDWG(ByVal strFile As String)





        Dim serv As New Services
        Dim db As New Database(False, False)

        Try

            db.ReadDwgFile(strFile, IO.FileShare.Read, False, Nothing)

        Catch ex As Exception

            MessageBox.Show("错误：" + ex.Message + "\n请确认文件未被其他程序占用")

            'Me.Cursor = Cursors.Default

            'lblMessage.Text = ex.Message

            Return

        End Try


        '该在哪里找到单位呢
        Dim i As Integer = db.Unitmode


        '计算目前的进度
        Dim dProcess As Double = 0
        Dim iCount As Integer = 1
        Dim iNow As Integer = 0


        Dim tm As TransactionManager = db.TransactionManager

        Using tr As Transaction = tm.StartTransaction()

            Try

                '关于计算进度的代码
                ' iCount = tm.GetAllObjects().Count



                'Dim bt As BlockTable = db.BlockTableId.Open(OpenMode.ForRead)
                Dim bt As BlockTable = tm.GetObject(db.BlockTableId, OpenMode.ForRead)

                Dim btr As BlockTableRecord = tm.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForRead)

                Dim iterator As BlockTableRecordEnumerator = btr.GetEnumerator()




                Dim id As ObjectId
                Dim obj As DBObject

                While iterator.MoveNext()

                    id = iterator.Current

                    obj = tm.GetObject(id, OpenMode.ForRead)

                    Dim ent As FEntity = Me.BuildShape(obj)
                    If ent IsNot Nothing Then

                        entList.Add(ent)
                    End If


                    '逐级累加
                    iNow += 1
                    '目前为止还没找到对应的总数获得方法
                    ' dProcess = (iNow / iCount) * 100
                    dProcess = iNow
                    bgwTran.ReportProgress(dProcess)


                End While


                tr.Commit()


            Catch ex As Exception

                MessageBox.Show(ex.Message)

                ' Me.Cursor = Cursors.Default

                'lblMessage.Text = ex.Message
                Return

            End Try




        End Using


        db.Dispose()
        serv.Dispose()




    End Sub

    Protected Sub AfterTran()



        Dim poly As ESMLineLayer

        m_manager.GetLayer("layer", poly)

        poly.AddEntityRange(entList)

        m_manager.Redraw()


        lblMessage.Text = "完成"

        fName = txtSave.Text.Trim()







        Me.Cursor = Cursors.Default


        SetToPreview()
    End Sub



    Dim nCount As Integer = 0
    Protected Function BuildShape(ByVal obj As DBObject) As FEntity

        Dim ptlist As New List(Of MapWinGIS.Point)

        Dim ent As New FEntity

        nCount += 1

        Select Case obj.GetType().Name
            Case "Line"
                Dim ln As Line = CType(obj, Line)
                Dim p1, p2 As DWGdirect.Geometry.Point3d
                p1 = ln.StartPoint
                p2 = ln.EndPoint

                ptlist.Add(Me.GetMPtFromP3d(p1))
                ptlist.Add(Me.GetMPtFromP3d(p2))

                ent.sn = nCount.ToString()
                ent.ptlist = ptlist.ToArray()
                ent.desc = ""

                Return ent


            Case "Polyline"

                Dim ply As Polyline = CType(obj, Polyline)

                Dim n As Integer = ply.NumberOfVertices()
                For i As Integer = 0 To n - 1

                    ptlist.Add(Me.GetMPtFromP3d(ply.GetPoint3dAt(i)))

                Next




                ent.sn = nCount.ToString()
                ent.ptlist = ptlist.ToArray()
                ent.desc = ""

                Return ent

            Case "Arc"

                Dim arc As Arc = CType(obj, Arc)
                Dim p As DWGdirect.Geometry.Point3d

                p = arc.Center
                Dim r As Double = arc.Radius



                'Dim p1, p2 As DWGdirect.Geometry.Point3d
                'p1 = arc.StartPoint
                'p2 = arc.EndPoint

                Dim a1, a2 As Double
                a1 = arc.StartAngle
                a2 = arc.EndAngle

                ptlist.AddRange(Me.BuildArc(Me.GetMPtFromP3d(p), r, a1, a2))




               

                ent.sn = nCount.ToString()
                ent.ptlist = ptlist.ToArray()
                ent.desc = ""

                Return ent





            Case "Circle"

                Dim cir As Circle = CType(obj, Circle)
                Dim p1 As DWGdirect.Geometry.Point3d

                Dim r As Double
                p1 = cir.Center
                r = cir.Radius

                ptlist.AddRange(Me.BuildCirclePoints(Me.GetMPtFromP3d(p1), r))

           

                ent.sn = nCount.ToString()
                ent.ptlist = ptlist.ToArray()
                ent.desc = ""

                Return ent



            Case "DBText"
                Dim text As DBText = CType(obj, DBText)

                Dim just As DWGdirect.DatabaseServices.AttachmentPoint = text.Justify

                Dim justReturn As TEXTJUSTIFICATION = TEXTJUSTIFICATION.RIGHT

                If just = AttachmentPoint.BaseLeft Or just = AttachmentPoint.BottomLeft Or just = AttachmentPoint.MiddleLeft Or just = AttachmentPoint.TopLeft Then
                    justReturn = TEXTJUSTIFICATION.LEFT

                Else
                    If just = AttachmentPoint.BaseCenter Or just = AttachmentPoint.BottomCenter Or just = AttachmentPoint.MiddleCenter Or just = AttachmentPoint.TopCenter Then
                        justReturn = TEXTJUSTIFICATION.CENTER

                    End If

                End If

                Dim rotation As Double = text.Rotation / (2 * Math.PI) * 360

                Dim ft As New FText(text.TextString, text.Position.X, text.Position.Y, rotation, justReturn)

                textList.Add(ft)

                Return Nothing


            Case "BlockReference"

                'Dim br As BlockReference = CType(obj, BlockReference)
                'Dim p1 As DWGdirect.Geometry.Point3d
                'p1 = br.Position


            Case "DBPoint"



            Case "Solid"

                'Dim sol As Solid = CType(obj, Solid)








            Case Else

                Return Nothing


        End Select

        Return Nothing

    End Function

    Protected Function BuildCirclePoints(ByVal p1 As MapWinGIS.Point, ByVal r As Double) As List(Of MapWinGIS.Point)




        '老板给出的另外的圆形测算方法
        Dim ptReturn As New List(Of MapWinGIS.Point)




        Dim pTemp As MapWinGIS.Point
        ' For i As Double = 0 To 2 * Math.PI Step Math.PI / 360

        For i As Double = 0 To 2 * Math.PI Step Math.PI / 36 '为了减小圆带来的文件压力，特别缩小10倍，来构建圆

            pTemp = New MapWinGIS.Point

            pTemp.x = r * Math.Cos(i) + p1.x
            pTemp.y = r * Math.Sin(i) + p1.y

            ptReturn.Add(pTemp)

        Next




        Return ptReturn







    End Function

    Public Function BuildArc(ByVal p1 As MapWinGIS.Point, ByVal r As Double, ByVal sAngle As Double, ByVal eAngle As Double) As List(Of MapWinGIS.Point)

        Dim ptReturn As New List(Of MapWinGIS.Point)

        '这里使用简化版的弧线取pi/36

        If sAngle < eAngle Then


            For i As Double = sAngle To eAngle Step Math.PI / 36
                Dim pTemp As New MapWinGIS.Point
                pTemp.x = r * Math.Cos(i) + p1.x
                pTemp.y = r * Math.Sin(i) + p1.y

                ptReturn.Add(pTemp)
            Next

        Else


            For i As Double = sAngle To eAngle + 2 * Math.PI Step Math.PI / 36
                Dim pTemp As New MapWinGIS.Point
                pTemp.x = r * Math.Cos(i) + p1.x
                pTemp.y = r * Math.Sin(i) + p1.y

                ptReturn.Add(pTemp)
            Next

        End If





        Return ptReturn


    End Function

    Public Function GetMPtFromP3d(ByVal p3d As DWGdirect.Geometry.Point3d) As MapWinGIS.Point
        Dim pt As New MapWinGIS.Point
        pt.x = p3d.X
        pt.y = p3d.Y

        Return pt

    End Function






    Dim m_layerHanle As Integer = -1



    Protected Sub RemoveLayer()


    End Sub

    Private Sub OnAskRemove(ByVal ln As String, ByVal sn As String)


        Dim cpLayer As EditableShapeLayer
        m_manager.GetLayer(ln, cpLayer)
        If cpLayer IsNot Nothing Then

            cpLayer.RemoveEntity(sn)
        End If


    End Sub

    Private Sub OnSelected(ByVal ln As String, ByVal sn As String)

        ' MessageBox.Show(sn)

    End Sub

    Protected Sub OnMPosChanged(ByVal x As Double, ByVal y As Double)
        '小阳修改
        coodor.Text = "X: " + x.ToString("f3") + "," + "Y:" + y.ToString("f3")
        'lblCoord.Text = "X: " + x.ToString("f3") + "," + "Y:" + y.ToString("f3")

    End Sub

    Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click

        OpenFileDialog1.Filter = "AutoCad DWG Files (*.dwg)|*.dwg"

        If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then

            txtFileName.Text = OpenFileDialog1.FileName

        Else
            Return
        End If

        Dim str As String = System.IO.Path.GetDirectoryName(txtFileName.Text.Trim())

        If str.LastIndexOf("\") = str.Length - 1 Then

            Dim output As String = System.IO.Path.GetDirectoryName(txtFileName.Text.Trim()) + System.IO.Path.GetFileNameWithoutExtension(txtFileName.Text.Trim()) + ".shp"
            txtSave.Text = output
        Else

            Dim output As String = System.IO.Path.GetDirectoryName(txtFileName.Text.Trim()) + "\" + System.IO.Path.GetFileNameWithoutExtension(txtFileName.Text.Trim()) + ".shp"
            txtSave.Text = output
        End If

        

    End Sub

    

   

    Protected Sub SetToPreview()
        If fName = "" Or Not System.IO.File.Exists(fName) Then

            MessageBox.Show("SHP文件丢失", "错误")
            Return
        End If

        m_manager.RemoveLayer("layer")

        Me.Cursor = Cursors.WaitCursor

        Dim shpFile As New MapWinGIS.Shapefile

        Dim b As Boolean = False
        b = shpFile.Open(fName)
        If Not b Then
            MessageBox.Show("SHP文件打开失败！")
            Return
        End If

        Dim sType As MapWinGIS.ShpfileType = shpFile.ShapefileType

        If shpFile.NumFields < 2 Then

            Dim f As New MapWinGIS.Field

            f = New MapWinGIS.Field
            f.Name = "Name"
            f.Type = MapWinGIS.FieldType.STRING_FIELD
            f.Width = 50

            Dim fd As New MapWinGIS.Field

            fd = New MapWinGIS.Field
            fd.Name = "desc"
            fd.Type = MapWinGIS.FieldType.STRING_FIELD
            fd.Width = 50


            shpFile.StartEditingShapes(True)
            shpFile.EditInsertField(f, 0)
            shpFile.EditInsertField(fd, 1)



            For i As Integer = 0 To shpFile.NumShapes

                shpFile.EditCellValue(0, i, i.ToString())
                shpFile.EditCellValue(1, i, i.ToString())

            Next

            shpFile.StopEditingShapes(True, True)

        End If




        shpFile.Save()
        shpFile.Close()

        Dim layer As EditableShapeLayer

        Dim ln As String = "layer"

        Select Case sType
            Case MapWinGIS.ShpfileType.SHP_POINT

                layer = New ESPointLayer(ln, New PointTool())
            Case MapWinGIS.ShpfileType.SHP_POLYLINE

                layer = New ESPolylineLayer(ln, New PolyTool())
            Case MapWinGIS.ShpfileType.SHP_POLYGON

                layer = New ESPolygonLayer(ln, New PolyTool())

            Case Else

                layer = New ESPolylineLayer(ln, New PolyTool())

        End Select



        m_manager.LoadLayer(layer, fName)


        '测试文字的效果啊
        Me.DrawText()

        Me.Cursor = Cursors.Default


    End Sub

    Private Sub AxMap1_DblClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxMap1.DblClick
        m_manager.SetToExtent()
    End Sub

    Private Sub AxMap1_PreviewKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles AxMap1.PreviewKeyDown

    End Sub

    Private Sub btnNormal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNormal.Click
        m_manager.SetMNormal()
        bLocation = False
    End Sub

    Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click
        m_manager.SetMSelect()
        bLocation = False
    End Sub

    Private Sub btnHand_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHand.Click
        m_manager.SetMHand()
        bLocation = False
    End Sub


    Public Event AskForAddDWGLayer(ByVal entList As List(Of FEntity), ByVal textList As List(Of FText))
    Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImport.Click

        '计算偏移值
        Dim pNow, pOld, pPre As New MapWinGIS.Point


        pOld.x = Double.Parse(lblX.Text)
        pOld.y = Double.Parse(lblY.Text)

        pNow.x = nudX.Value
        pNow.y = nudY.Value

        pPre.x = pNow.x - pOld.x
        pPre.y = pNow.y - pOld.y

        If pPre.x = 0 And pPre.y = 0 Then
        Else

            '实体偏移
            For Each ent As FEntity In entList

                For i As Integer = 0 To ent.ptlist.Length - 1

                    ent.ptlist(i).x += pPre.x
                    ent.ptlist(i).y += pPre.y

                Next

            Next


            '文字偏移
            For Each text As FText In textList

                text.x += pPre.x
                text.y += pPre.y

            Next


        End If


        Dim lay As New DWGShapeLayer(lName, textList, entList)

        mRef.AddLayer(lay)




        MessageBox.Show("主场景导入完成！")

        mRef.SetZoomToLayer(lName)
        Me.Close()

        'RaiseEvent AskForAddDWGLayer(entList, textList)

        'Me.Close()




        'Dim layer As ESPolylineLayer
        'm_manager.GetLayer("layer", layer)
        'If layer IsNot Nothing Then

        '    layer.RemoveAllEntity()
        '    layer.AddEntityRange(entList)

        '    layer.Save()

        'Else

        '    MessageBox.Show("请先转换对应的文件")
        '    Return

        'End If














        '下面的代码代表的是图层单个图形的添加，目前已经废弃了，日后再慢慢研究

        'Dim lst As List(Of String)
        'lst = m_manager.GetSelectedShapeNames()
        'If lst.Count < 1 Then
        '    MessageBox.Show("至少选择一个图形导入！")

        '    Return
        'End If

        'Dim layer As EditableShapeLayer
        'm_manager.GetLayer("layer", layer)
        'If layer Is Nothing Then
        '    Return

        'End If

        'Dim lstReturn As New List(Of FEntity)

        'For Each str As String In lst

        '    Dim en As FEntity = layer.GetEntity(str)

        '    If en IsNot Nothing Then

        '        For i As Integer = 0 To en.ptlist.Length
        '            en.ptlist(i).x += nudX.Value
        '            en.ptlist(i).y += nudY.Value

        '        Next

        '        lstReturn.Add(en)

        '    End If

        'Next


        'Dim lname As String = ""

        'RaiseEvent AskForImportEntity(lname, lstReturn)

        ''到处后的默认处理是什么呢，这里暂时用删除
        'For Each str As String In lst

        '    layer.RemoveEntity(str)

        'Next


    End Sub



    Private Sub GroupBox1_Enter_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter

    End Sub

    Private Sub btnSaveS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveS.Click

        'fol.Filter = "ESRI SHP Files (*.shp)|*.shp"

        FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.Desktop
        If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then

            txtSave.Text = FolderBrowserDialog1.SelectedPath + "temp.shp"

        End If



    End Sub

 

    Dim m_iDraw As Integer = 0
    Private Sub DrawText()
        AxMap1.ClearDrawing(m_iDraw)
        m_iDraw = AxMap1.NewDrawing(MapWinGIS.tkDrawReferenceList.dlSpatiallyReferencedList)

        AxMap1.set_DrawingLabelsScale(m_iDraw, True)

        For Each dbt As FText In textList

            Dim just As MapWinGIS.tkHJustification = MapWinGIS.tkHJustification.hjRaw

            Select Case dbt.justification

                Case TEXTJUSTIFICATION.CENTER
                    just = MapWinGIS.tkHJustification.hjCenter

                Case TEXTJUSTIFICATION.LEFT
                    just = MapWinGIS.tkHJustification.hjLeft

                Case TEXTJUSTIFICATION.RIGHT
                    just = MapWinGIS.tkHJustification.hjRight


            End Select



            AxMap1.AddDrawingLabel(m_iDraw, dbt.str, 1000, dbt.x, dbt.y, just)


        Next

    End Sub

    Private Sub nudX_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudX.ValueChanged

    End Sub

    Dim bLocation As Boolean = False
    Private Sub btnLocation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLocation.Click

        m_manager.SetAllLayerNoEdditable()

        AxMap1.MapCursor = MapWinGIS.tkCursor.crsrCross

        bLocation = True

    End Sub

    Private Sub SetNotLocation()
        AxMap1.MapCursor = MapWinGIS.tkCursor.crsrMapDefault
        bLocation = False
    End Sub


    Dim m_iDaw2 As Integer = -1
    Protected Sub DrawConcernPoint(ByVal pt As MapWinGIS.Point)
        AxMap1.ClearDrawing(m_iDaw2)
        m_iDaw2 = AxMap1.NewDrawing(MapWinGIS.tkDrawReferenceList.dlSpatiallyReferencedList)

        AxMap1.DrawCircleEx(m_iDaw2, pt.x, pt.y, 4, 65025, True)


    End Sub

    Private Sub AxMap1_MouseDownEvent(ByVal sender As System.Object, ByVal e As AxMapWinGIS._DMapEvents_MouseDownEvent) Handles AxMap1.MouseDownEvent
        If bLocation Then
            If e.button = 1 Then

                Dim p As New MapWinGIS.Point
                AxMap1.PixelToProj(e.x, e.y, p.x, p.y)

                Me.DrawConcernPoint(p)

                lblX.Text = p.x.ToString("f2")
                lblY.Text = p.y.ToString("f2")

            ElseIf e.button = 2 Then


                Me.SetNotLocation()

            End If

          

        End If
    End Sub

    Private Sub GroupBox3_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox3.Enter

    End Sub

    Private Sub Label10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label10.Click, Label11.Click

    End Sub

    Private Sub lblY_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblY.Click

    End Sub

    Private Sub bgwTran_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgwTran.DoWork



        Dim strFileName As String = txtFileName.Text.Trim()
        TranslateDWG(strFileName)

    End Sub


    Private Sub bgwTran_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgwTran.RunWorkerCompleted
        If e.Error IsNot Nothing Then
            MessageBox.Show(e.Error.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        Else

            If e.Cancelled Then

                MessageBox.Show("取消操作！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Return
            End If




            AfterTran()


            MessageBox.Show("转换操作成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)


        End If





    End Sub

    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        m_manager.SetMHand()
        bLocation = False
    End Sub

    Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
        m_manager.SetMSelect()
        bLocation = False
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        m_manager.SetMNormal()
        bLocation = False
    End Sub


    ''' <summary>
    ''' 更新进度条
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub bgwTran_ProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles bgwTran.ProgressChanged


        ' ProgressBar1.Value = e.ProgressPercentage
        lblCount.Text = e.ProgressPercentage.ToString()

    End Sub


End Class

